﻿#if NET5_0_OR_GREATER
using System;

using zijian666.Converts.Abstractions;
using zijian666.Converts.Core;

namespace zijian666.Converts.Translator;
/// <summary>
/// 将 <seealso cref="DateOnly"/> 和 <seealso cref="TimeOnly"/> 转为 <seealso cref="DateTime"/>
/// </summary>
public class DateTimeTranslator : ITranslator
{
    /// <inheritdoc />
    public bool TryTranslate(IConvertContext context, object? input, out object? translated)
    {
        translated = input switch
        {
            DateOnly date => date.ToDateTime(TimeOnly.MinValue),
            TimeOnly time => UTCHelper.LocalEpoch.Add(time.ToTimeSpan()),
            _ => null,
        };
        return translated != null;
    }
}
#endif